home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / SPLINE.ZIP / SPLINE.TXT < prev    next >
Encoding:
Text File  |  1997-03-10  |  18.8 KB  |  421 lines

  1. **************************************************************************
  2. **************************************************************************
  3.               SPLINE GENERATOR FOR PERSISTENCE OF VISION 3.x
  4. **************************************************************************
  5. **************************************************************************
  6.  
  7. Created by Chris Colefax, February 1997
  8.  
  9. 1.0  INSTALLATION
  10. 2.0  QUICK START
  11. 3.0  CREATING SPLINE FILES
  12.         3.1  CREATING MULTIPLE SEGMENTS IN A SPLINE FILE
  13.         3.2  CREATING A LOOPING SPLINE
  14.         3.3  CREATING STRAIGHT LINE SEGMENTS
  15.         3.4  CREATING SHARP CORNERS
  16.         3.5  USING SPLINER.INC
  17. 4.0  USING SPLINE FILES IN POVRAY SCENE FILES
  18.         4.1  PREVIEWING A SPLINE
  19.         4.2  USING A SPLINE FOR ANIMATION
  20.         4.3  CREATING SPLINE BASED OBJECTS
  21. 5.0  CONTACTING THE AUTHOR
  22.  
  23. **************************************************************************
  24.  
  25.  
  26. 1.0  INSTALLATION
  27. **************************************************************************
  28. Copy the three POVRay include files (Spline.inc, SplineR.inc, ShowSpl.inc)
  29. to one of the directories (folders) in your POVRay library path.  Normally
  30. this is the INCLUDE sub-directory of the directory where you installed
  31. POVRay, so if you installed POVRay in C:\POVRAY you should copy the
  32. include files to C:\POVRAY\INCLUDE.  On a Windows 95 system, this is
  33. probably something like:
  34.  
  35.    C:\Program Files\POV-Ray for Windows\Include
  36.  
  37. On UNIX and similar systems, where filenames are case-sensitive, you may
  38. have to rename the includes file to Spline.inc, SplineR.inc, and
  39. ShowSpl.inc, rather than all uppercase or all lowercase.  If you want to
  40. render the sample files you should also check that the naming of Smooth.spl,
  41. Unsmooth.spl, Landscap.pov, and Map.gif are as shown.  This will enable you
  42. to render the sample files without modification.
  43.  
  44.  
  45. 2.0  QUICK START
  46. **************************************************************************
  47. The POVRay Spline Generator allows you to create smooth spline objects for
  48. use in a POVRay scene file simply by specifying a number of control
  49. points, in a similar way to POVRay's lathe, prism, and surface-of-
  50. revolution (sor) objects.  However, with the POVRay Spline Generator you
  51. can specify your control points using three-dimensional vectors, and the
  52. generator will automatically calculate a smooth spline that passes through
  53. each point!  You can then use the splines to position your camera,
  54. light_sources, and objects in animations, or to create smooth spline-based
  55. objects.
  56.  
  57. The first step when using the spline generator is to create a spline file
  58. which specifies the control points of the spline.  Then you specify how
  59. far along the spline you wish to move and the generator will give you a
  60. vector indicating the current position of the spline, eg. If you have
  61. created a spline file called "MySpline.spl" and wish to know the position
  62. of this spline halfway along its length, you would add the following lines
  63. to your scene file:
  64.  
  65.    #declare spline_clock = .5
  66.    #include "MySpline.spl"
  67.  
  68. The generator would then create a variable called "spline_pos" which
  69. contains the position halfway along the spline, which you can now use to 
  70. position your object, camera, etc, eg:
  71.  
  72.    camera {location spline_pos look_at <0, 0, 0>}
  73.    object {MyObject translate spline_pos + <10, 5, 0>}
  74.  
  75.  
  76. 3.0  CREATING SPLINE FILES
  77. **************************************************************************
  78. Before you can use the spline generator you must create a spline file,
  79. which contains a list of the points needed to define the spline, as well
  80. as other options you can use to modify the spline.
  81.  
  82. Each spline is made up of a number of segments, each segment being a
  83. smooth curve which joins two points (point1 and point2).  In addition to
  84. these two points you must also specify two other points for each segment
  85. which control the curvature of that segment (point0 and point3).  After
  86. declaring these four points you then include the spline generator file.
  87.  
  88. A simple curved spline file would look like this:
  89.  
  90.    #declare point0 = <-5, -3, -5>
  91.    #declare point1 = <-5,  0, -5>
  92.    #declare point2 = < 5,  0,  5>
  93.    #declare point3 = < 5, -3,  5>
  94.    #include "Spline.inc"
  95.  
  96. This would create a curve which goes from point1 <-5, 0, -5> to point2
  97. <5, 0, 5>.  Because of the positions of the curve control points (point0
  98. and point3) the curve would arch upwards in the middle.  How do we know 
  99. this?  Well, we can see that point0 is 3 units 'below' point1 (we shall
  100. consider that +y is up), and that point3 is 3 units below point2.
  101.  
  102. Now imagine drawing a line up from point0 to point1, and then continuing
  103. the line a little above point1.  The direction of this line is the
  104. direction that the spline starts moving in as it leaves point1.
  105.  
  106. Now, do a similar thing with point2 and point3, drawing a line up from
  107. point3 to a little past point2.  The direction of this line is the
  108. direction that the spline will be moving as it reaches point2.
  109.  
  110. To create the curve the spline generator will start at point1, facing in
  111. the direction of the line from point0 to point1. It will then start moving
  112. in that direction, as well as moving towards point2.  Then, as it nears
  113. point2 it will make sure that it is facing in the direction from point2 to
  114. point3, until it finally reaches point2.
  115.  
  116. Therefore, if we had #declared point0 = <-5, 3, -5> we can see that this
  117. would change the shape of the curve.  Because the direction from point0 to
  118. point1 is now downwards the spline would move down at the start rather than
  119. up.  Because we haven't changed point3 the spline would still have to move
  120. down as it reached the end (point2).  To do this it would have to move up
  121. somewhere in the middle, so that it is above point2.  This is exactly what
  122. it does!
  123.  
  124. So, we can see how the directions from point0 to point1 and from point2 to
  125. point3 are used to set the curvature of the spline.  In addition, the
  126. size of these distances will also alter the shape of the spline, eg. if we
  127. had #declared point0 = <-5, -10, -5> and #declared point3 = <5, -10, 5> the
  128. curve would arch upwards much higher in the middle, because the lengths of
  129. the lines from point0 to point1 and point2 to point3 are much greater.
  130.  
  131. If we had #declared point0 = <-5, -1, -5> and #declared point3 = <5, -1, 5> 
  132. the curve wouldn't arch upwards very much at all, because the lengths of
  133. the lines from point0 to point1 and point2 to point3 are quite small
  134. compared to the distance between point1 and point2.
  135.  
  136.  
  137. 3.1  CREATING MULTIPLE SEGMENTS IN A SPLINE FILE
  138. **************************************************************************
  139. The example spline above consists of only one segment, the shape of which
  140. is determined by four points.  You can, however, create splines with as
  141. many segments as you want, each segment being a different curve.  The
  142. spline generator will join up all the curves to create one long spline.
  143.  
  144. To create a multiple segment spline file, you must specify the number of
  145. segments in the spline.  Then you create the first segment exactly as
  146. above.  Finally, for each segment after the first you must specify the next
  147. point to move to, and the point to determine the curvature of the spline
  148. as it reaches this next point.  You do this by redeclaring point2 and 
  149. point3, and including the spline generator file again, eg. for a three 
  150. segment curve:
  151.  
  152.    #declare spline_segments = 3
  153.  
  154.    #declare point0 = <-15, -3, 5> #declare point1 = <-15,  0, 5>
  155.    #declare point2 = < -5,  0, 0> #declare point3 = < -5, -3, 0>
  156.    #include "Spline.inc"
  157.  
  158.    #declare point2 = <5, 0, 0> #declare point3 = <5, 3, 0>
  159.    #include "Spline.inc"
  160.  
  161.    #declare point2 = <15, 0, 0> #declare point3 = <15, -3, 0>
  162.    #include "Spline.inc"
  163.  
  164. This will create a smooth spline that goes from point1 <-15, 0, 5> to
  165. point2 <-5, 0, 0>, to the next point2 <5, 0, 0>, to the next point2
  166. <15, 0, 0>.  The other points are used to curve the spline is a smooth 'M'
  167. shape.  After the first segment you don't have to worry about point0 and
  168. point1, because the spline generator will automatically join the last
  169. point of the previous segment to the next point2 specified.
  170.  
  171. The one thing to make sure of is that you #include "Spline.inc" after each 
  172. segment (the number of times this line appears in the spline file should 
  173. always be equal to spline_segments).
  174.  
  175.  
  176. 3.2  CREATING A LOOPING SPLINE
  177. **************************************************************************
  178. If you wish to create a looping spline (eg. for a continuously looping
  179. animation) you simply add the following line to the spline file:
  180.  
  181.    #declare spline_loop = true
  182.  
  183. The spline generator will then join the last point of the spline to the
  184. first point with a smooth curve segment, creating a spline that moves in
  185. an unbroken loop (see "Smooth.spl" for an example of this).
  186.  
  187.  
  188. 3.3  CREATING STRAIGHT LINE SEGMENTS
  189. **************************************************************************
  190. Normally you use point0 and point3 to curve the spline in different ways,
  191. depending on the shape you want the spline to have.  If, however, you want
  192. parts of the spline to be completely straight, just set point0 to be the
  193. same as point1 (if you want a straight line at the beginning of the
  194. spline), and set point3 to the same as point2 (if you want a straight line
  195. anywhere else in the spline).  The following would create a spline made up
  196. of straight line segments:
  197.  
  198.    #declare spline_segments = 2
  199.  
  200.    #declare point0 = < 0,  0,   0> #declare point1 = <0,   0,   0>
  201.    #declare point2 = <10, 10, -10> #declare point3 = <10, 10, -10>
  202.    #include "Spline.inc"
  203.  
  204.    #declare point2 = <15, -10, 10> #declare point3 = <15, -10, 10>
  205.    #include "Spline.inc"
  206.  
  207.  
  208. 3.4  CREATING SHARP CORNERS
  209. **************************************************************************
  210. By default the spline generator will create a smooth-cornered spline (ie.
  211. the join between each segment is completely smooth).  If you want to
  212. create a spline with sharp corners where two segments join up you must
  213. not only redeclare point2 and point3, but point0 as well (you should never
  214. have to redeclare point1, as this would create a spline with gaps between
  215. segments).
  216.  
  217. Because point0 is used to determine the direction at the start of the
  218. spline segment, altering this for a segment after the first segment will
  219. result in sharp corners (normally the generator uses the same direction as
  220. at the end of the previous segment).  The following would create a spline
  221. that passes through the same points as the example spline in section 3.1,
  222. but because point0 has been redeclared for each segment it will create a
  223. spline with three arches and sharp corners, rather than a smooth 'M' shape.
  224.  
  225.    #declare spline_segments = 3
  226.  
  227.    #declare point0 = <-15, -3, 5> #declare point1 = <-15,  0, 5>
  228.    #declare point2 = < -5,  0, 0> #declare point3 = < -5, -3, 0>
  229.    #include "Spline.inc"
  230.  
  231.    #declare point0 = <-5, -3, 0>
  232.    #declare point2 = < 5,  0, 0> #declare point3 = <5, -3, 0>
  233.    #include "Spline.inc"
  234.  
  235.    #declare point0 = < 5, -3, 0>
  236.    #declare point2 = <15,  0, 0> #declare point3 = <15, -3, 0>
  237.    #include "Spline.inc"
  238.  
  239. See "UnSmooth.spl" for an example of a spline file with sharp corners.
  240.  
  241.  
  242. 3.5  USING SPLINER.INC
  243. **************************************************************************
  244. When you use Spline.inc to create your spline file the vector you specify
  245. for each point (including curve control points) indicates the absolute
  246. position of that point relative to the origin, eg. specifying point0 =
  247. <-5, -3, -5> and point1 = <-5, 0, -5> will create a spline that starts
  248. in a direction parallel to the y axis because that is the direction
  249. between the two points.
  250.  
  251. If you prefer, however, you can use the "SplineR.inc" file to create
  252. spline files for which you can specify relative curve control points
  253. rather than absolute control points.  The following two code examples
  254. would result in exactly the same spline:
  255.  
  256.    #declare point0 = <-5, -3, -5> #declare point1 = <-5,  0, -5>
  257.    #declare point2 = < 5,  0,  5> #declare point3 = < 5, -3   5>
  258.    #include "Spline.inc"
  259.  
  260. is the same as:
  261.  
  262.    #declare point0 = <0, -3, 0> #declare point1 = <-5,  0, -5>
  263.    #declare point2 = <5,  0, 5> #declare point3 = < 0, -3   0>
  264.    #include "SplineR.inc"
  265.  
  266. The only difference is that point0 and point3 have been specified relative
  267. to point1 and point2 (respectively).  This allows you to change point1 and
  268. point2 without having to worry about maintaining the same directions for
  269. the curve control lines.  Note that Spline.inc and SplineR.inc should not
  270. be used in the same multi-segment spline file or you will get unexpected
  271. results (see "UnSmooth.spl" for an example of a spline file that uses 
  272. SplineR.inc).
  273.  
  274.  
  275. 4.0  USING SPLINE FILES IN POVRAY SCENE FILES
  276. **************************************************************************
  277. After you have created your spline file with the necessary control points
  278. and spline options, you are ready to use the spline in your POVRay scene
  279. files.
  280.  
  281. 4.1  PREVIEWING A SPLINE
  282. **************************************************************************
  283. You can create a simple rendered image of your spline using the
  284. "ShowSpl.inc" file.  Just create a scene file with the following code:
  285.  
  286.    #declare spline_file = "MySpline.spl"
  287.    #include "ShowSpl.inc"
  288.  
  289. Then add a suitable camera to specify where you want to view your spline
  290. from, and when you render the scene file you will get an image that plots
  291. the shape of the spline.  This is useful when setting up a spline file
  292. and trying to determine the correct points to use (see "SP_Samp1.pov" and
  293. "SP_Samp2.pov"), and it is especially helpful when creating a spline to
  294. position a camera, as you can add the above two lines of code to your scene
  295. and check that the camera does not pass through any solid objects, etc.
  296. (see "PFlyAnim.pov" for an example of this technique).
  297.  
  298. In addition to the spline_file variable you can declare the following
  299. BEFORE including "ShowSpl.inc":
  300.  
  301. 1.  spline_smoothness
  302.    This determines the number of points of the spline plotted, eg:
  303.       #declare spline_smoothness = 200
  304.    will result in a much smoother spline, although it will take longer to
  305.    parse and render.
  306.  
  307. 2.  spline_object
  308.    By default the spline is plotted using unit-sized spheres, bright white
  309.    spheres.  You can change this object definition to plot the spline with
  310.    a differently shaped or coloured object, eg:
  311.  
  312.       #declare spline_object = box {<-1, -1, -1>, <1, 1, 1>
  313.          texture {Box_Texture}}
  314.  
  315.    Note that the object should generally be centred around the origin, or
  316.    the spline preview will be in the wrong position.
  317.  
  318.  
  319. 4.2  USING A SPLINE FOR ANIMATION
  320. **************************************************************************
  321. To use a spline file to position an object, camera, light_source, etc. you
  322. must first specify the "spline_clock" variable.  This determines how far
  323. along the spline you wish to move, and should generally range from 0 (the
  324. start of the spline) to 1 (the end of the spline).  If you specify a value
  325. outside this range the spline generator will automatically loop back to
  326. the beginning of the spline (if you use a number over 1) or to the end (if
  327. you specify a number less than 0), eg:
  328.  
  329.    #declare spline_clock = 1.5
  330.  
  331. would be the same as #declare spline_clock = .5, and would give the spline 
  332. position halfway along the spline.
  333.  
  334. In animations you will generally want the spline_clock to be equal to
  335. POVRay's internal clock variable, and if this is the case you can simply
  336. not specify any spline_clock at all and the spline generator will auto-
  337. matically use the clock variable in its place.
  338.  
  339. If you want to loop through the spline more than once you should specify
  340. spline_clock to be a multiple of the clock variable, eg:
  341.  
  342.    #declare spline_clock = clock * 5
  343.  
  344. This will loop through the spline 5 times.  Also, You can 'phase shift'
  345. the spline by adding an amount to the clock, eg:
  346.  
  347.    #declare spline_clock = clock + .5
  348.  
  349. This is useful when you want the spline to start somewhere other than the
  350. beginning, or if you want to use one spline for both the location and
  351. look_at variables of a camera ,eg:
  352.  
  353.    camera {
  354.       #declare spline_clock = clock #include "CamPath.spl"
  355.          location spline_pos
  356.       #declare spline_clock = clock + .1 #include "CamPath.spl"
  357.          look_at spline_pos}
  358.  
  359. This will cause the camera to look slightly ahead of itself along the
  360. spline, while still changing direction with the spline (see "FlyAnim.pov").
  361.  
  362. After you have declared your spline_clock you must then include the spline
  363. file you wish to use, as shown in the camera statement above.  The spline
  364. generator will then calculate the "spline_pos" variable which will contain
  365. the vector location of the spline at the distance along the spline
  366. specified by the spline_clock variable.  You can then use this vector
  367. anywhere that vectors are accepted (eg. translations, rotations, colors) or
  368. you can use the individual components of the vector as float values (eg.
  369. spline_pos.x will return the x-coordinate of the spline position, see
  370. "BallAnim.fli" for an example).
  371.  
  372. Note that you can modify the spline_pos variable to translate or scale the
  373. entire spline without having to edit the spline file, eg:
  374.  
  375.    object {MyObject translate spline_pos * 1.5 + <4, -5, -10>}
  376.  
  377. This will scale the spline path by 1.5 and translate it by <4, -5, -10>
  378. without affecting the size of the object being translated.
  379.  
  380.  
  381. 4.3  CREATING SPLINE BASED OBJECTS
  382. **************************************************************************
  383. In addition to using splines for moving objects along paths in animations
  384. you can use them to create static objects.  Basically you set up a scene
  385. file like this:
  386.  
  387.    #declare spline_clock = 0 #while (spline_clock <= 1)
  388.       #include "MySpline.spl"
  389.       object {MyObject translate spline_clock}
  390.    #declare spline_clock = spline_clock + (1 / 40) #end
  391.  
  392. For a more complicated scene file that uses this method see the
  393. "Tentacle.pov" example file.  You could use a similar method to create
  394. objects such as ropes, neon lettering, railways, roller coasters, and a
  395. variety of organic shapes.
  396.  
  397. In fact, you could even create an animated spline object by creating
  398. individual spline files to specify the control points of another spline
  399. file, and use this to create a moving object!
  400.  
  401.  
  402. 5.0  CONTACTING THE AUTHOR
  403. **************************************************************************
  404. If you wish to contact me with bug reports, bug fixes, criticisms, 
  405. comments, suggested improvements, questions, etc. you can reach me by 
  406. email at:
  407.  
  408.    ccolefax@geocities.com
  409.  
  410. or by regular mail at:
  411.  
  412.    Chris Colefax
  413.    P.O. Box 110
  414.    Kuranda, Queensland
  415.    Australia  4872
  416.  
  417. **************************************************************************
  418.  
  419. POV-Ray(tm) and Persistence of Vision(tm) are registered trademarks of the
  420. POV-Ray Team(tm)
  421.